<?php
	session_start();

 	$index='index.php';
	$admin='admin.php';

	if (!isset($_SESSION['login']))  {
	 header(sprintf("Location: %s",$index));
	 exit;
	}


	include ("config.inc.php");


	if (isset($_POST['s']) && $_POST['s']=='form1'){

		$desc_defeito=$_POST['desc_defeito'];
		$patrimonio=$_POST['patrimonio'];
		$protocolo=$_POST['protocolo'];
		$usuario=$_POST['usuario'];
		$status=$_POST['status_os'];
		$data_chamado=date("Y-m-d H:i:s");


   if(empty($desc_defeito)){
         $inf = "<center><font color=#FFFF00>Favor preencher o campo DESCRI&Ccedil;&Atilde;O DO DEFEITO.</font>"; $erro++;
   }


   if($erro==0){

		$sql="INSERT INTO chamados" .
       		" (id_usuario, " .
       		" data_abertura, ".
       		" descricao_falha, " .
       		" patrimonio, " .
       		" protocolo, " .
       		" id_status )" .
       		" VALUES (" .
       		" $usuario,'$data_chamado','$desc_defeito','$patrimonio','$protocolo',$status) ";


       	if (mysql_query($sql)){
			$inf = "<center><font color=#00FF00>Dados gravados com sucesso!<br>O n&uacute;mero de protocolo de sua solicita&ccedil;&atilde;o &eacute;: ".$protocolo; $erro++;
			echo $inf;
       	}

   }

} else {

?>
<html>
<head>
<title>STI - Suporte T&eacute;cnico em Inform&aacute;tica</title>

<script type="text/javascript">
function ligar_relogio(){
UR_Nu = new Date;
UR_Indhold = showFilled(UR_Nu.getHours()) + ":" + showFilled(UR_Nu.getMinutes()) + ":" + showFilled(UR_Nu.getSeconds());
document.getElementById("relogio").innerHTML = UR_Indhold;
setTimeout("ligar_relogio()",1000);
}
function showFilled(Value){return (Value > 9) ? "" + Value : "0" + Value;}
</script>

<script>
	function mascara(src, mask){
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida)
	{
	src.value += texto.substring(0,1);
	}
	}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />

	<script type='text/javascript' src='relojdhtml.js'></script>

</head>
<body>
<p align=center><img src="imagens/cbtu-stujop.png"/></p>
<table align="center" width="60%">
<tr>
<td align="left">Jo&atilde;o Pessoa/PB</td>
<td align="right"><?php echo date("d/m/Y");?> <span><b><span id="relogio"></b></span><script>ligar_relogio();</script></span> </td>
</tr>
</table>
<hr />
<br />
<table align="center" border="0">
<tr>
 <td><b>
    <?php
     $hr = date(" H ");
     if($hr >= 12 && $hr<18) {
     $resp = "Boa tarde.";}
     else if ($hr >= 0 && $hr <12 ){
     $resp = "Bom dia.";}
     else {
     $resp = "Boa noite.";}
     echo "$resp ";
?>
Por favor preencha o formul&aacute;rio abaixo descrevendo o defeito ou <a href='principal.php'>clique aqui para voltar.</a><br><br>
</b><br></td>
</tr>_
</table>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table align=center border=1>
<tr>
<td colspan=4>DADOS PARA ABERTURA DO CHAMADO</td>
</tr>
<tr>
<td colspan=3><?php if (isset($inf)){ for($i=0;$i<count($inf);$i++){ echo $inf[$i]; } } ?></td>
</tr>
<tr>
<td>Nome:</td>
<td>Setor:</td>
<td>Ramal:</td>
</tr>_
<td><input type="text" size=30 name="nome" value="<?php echo $_SESSION['nome'];?>" READONLY/></td>
<td><input type="text" name="setor" value="<?php echo $_SESSION['setor'];?>" READONLY /></td>
<td><input type="text" name="ramal" value="<?php echo $_SESSION['ramal'];?>" READONLY /></td>
<tr>
<td colspan=3>Descri&ccedil;&atilde;o do defeito:</td>
</tr>
<tr>
<td colspan=3><textarea type="text" cols="80" rows="3" name="desc_defeito" maxlength=50></textarea></td>
</tr>
<tr>
<td colspan="2">Patrim&ocirc;nio:</td><td>protocolo</td>
</tr>
<tr>
	<td colspan="2"><input type="text" size=30 name="patrimonio" onkeypress="mascara(this, '########')" maxlength=8 /></td>
	<td><input type="text" name="protocolo"/></td>
</tr>
<tr>
	<td colspan="3">
		<input name="usuario"  type="hidden" value="<?php echo $_SESSION['id_user']; ?>"/>
		<input name="status_os"  type="hidden" value="1"/>
	</td>
</tr>
<tr><td align="right" colspan=4> <input name="s" type="hidden" id="s" value="form1"/>
<input type="submit" value="ENVIAR"></td></tr>
</table>
</form>
</body>
</html>
<?PHP
	}
?>
